feat: native Anthropic passthrough for Claude models#246
Open
jackylam0812 wants to merge 1 commit intoericc-ch:masterfrom
Open
feat: native Anthropic passthrough for Claude models#246jackylam0812 wants to merge 1 commit intoericc-ch:masterfrom
jackylam0812 wants to merge 1 commit intoericc-ch:masterfrom
Conversation
Route Claude model requests directly to Copilot's native /v1/messages endpoint instead of translating through OpenAI /chat/completions. Benefits: - Eliminates Anthropic↔OpenAI translation overhead for Claude models - Enables native thinking (adaptive), cache_control, output_config - Streaming SSE directly piped (zero translation latency) - Non-Claude models (GPT etc.) keep existing OpenAI translation path New files: - src/services/copilot/create-messages.ts - Native /v1/messages client - src/lib/sanitize.ts - Copilot backend compatibility sanitizer - Strips unsupported fields (context_management, budget_tokens, etc.) - opus: thinking.enabled→adaptive, effort→medium - Model name normalization (claude-sonnet-4-* → claude-sonnet-4) Modified: - src/routes/messages/handler.ts - Route Claude vs non-Claude models All 42 existing + new tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Route Claude model requests directly to Copilot's native
/v1/messagesendpoint instead of translating through OpenAI/chat/completions.Motivation
The current architecture translates every request through an Anthropic ↔ OpenAI format conversion layer. However, GitHub Copilot exposes a native Anthropic
/v1/messagesendpoint that accepts Claude requests directly. By bypassing the translation for Claude models, we get:thinking.type: "adaptive"works out of the boxChanges
New files
src/lib/sanitize.ts— Copilot backend compatibility sanitizercontext_management,budget_tokens,defer_loading,tool_reference)thinking.enabled→adaptive, effort →mediumclaude-sonnet-4-*→claude-sonnet-4)src/services/copilot/create-messages.ts— Native/v1/messagesclienttests/sanitize.test.ts— 16 test cases for the sanitizerModified
src/routes/messages/handler.ts— Routes Claude models to native path, non-Claude models keep existing OpenAI translationRouting logic
Test results
All 42 tests pass (26 existing + 16 new sanitizer tests).
Breaking changes
None. Non-Claude models (GPT, etc.) are completely unaffected.